package com.paolu.filestream;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class Input {

    public Input(String filePath) {
        for (int i = 0; i < 5; i++) {
            input(filePath);
        }
    }

    private void input(String filePath) {
        Random random = new Random();

        Set<Integer> redNumbersSet = new HashSet<>();
        while (redNumbersSet.size() < 6) {
            int redNumber = random.nextInt(33) + 1;
            redNumbersSet.add(redNumber);
        }

        int[] redNumbers = redNumbersSet.stream().mapToInt(Integer::intValue).toArray();

        Arrays.sort(redNumbers);

        int blueNumber = random.nextInt(16) + 1;

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true))) {
            writer.write("redNumbers: " + Arrays.toString(redNumbers));
            writer.newLine();
            writer.write("blueNumber: " + blueNumber);
            writer.newLine();
        } catch (IOException e) {
            System.out.println("发生错误: " + e.getMessage());
        }
    }
}
